import { useMessage, useDialog, useNotification, useLoadingBar } from 'naive-ui';
import {Component, ComponentProps, Hook, VueComponent} from "vue3-oop";
import http from "@/api/http";
import EmptyDialog from '@/components/tool/EmptyDialog'

interface IProps {}
// @Component()
export default class GlobalInject extends VueComponent<IProps> {
  static defaultProps: ComponentProps<IProps> = []

  constructor(
  ) {
    super();
  }

  @Hook('Mounted')
  onMounted(){
    // mount on window
    window.$message = useMessage()
    window.$dialog = useDialog()
    window.$notification = useNotification()
    window.$loadingBar = useLoadingBar()
    window.$http = http;
    window.$popUp = EmptyDialog.open

    const {clientWidth:width,clientHeight:height} = window.document.body;
    window.$size = ref({width, height}).value;

    window.onresize=()=>{
      const {clientWidth:width,clientHeight:height} = window.document.body;
      window.$size.width = width;
      window.$size.height = height;
    };
  }

  @Hook('Unmounted')
  onUnmounted(){
  }

  render() {
    return (
      <>{useSlots().default!()}</>
    )
  }
}

